﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Win8Start.UI
{
	public partial class MenuItemControl : UserControl
	{
		public MenuItemControl()
		{
			InitializeComponent();
		}

		private Shortcut _shortcut = null;
		public Shortcut Shortcut
		{
			get { return _shortcut; }
			set
			{
				_shortcut = value;
				if (_shortcut != null)
				{
					SetToolTip(_shortcut.FileName);
					AppIcon.Image = _shortcut.Icon.ToBitmap();
					Caption = System.IO.Path.GetFileNameWithoutExtension(_shortcut.FileName);
				}
			}
		}

		public void SetToolTip(string _FileName)
		{
			toolTip1.SetToolTip(this, _FileName);
			foreach (Control c in this.Controls)
			{
				toolTip1.SetToolTip(c, _FileName);
			}
		}

		public string Caption
		{
			get { return AppName.Text; }
			set { AppName.Text = value; }
		}

		protected override void OnMouseLeave(EventArgs e)
		{
			if (this.ClientRectangle.Contains(this.PointToClient(Control.MousePosition)))
				return;
			else
			{
				base.OnMouseLeave(e);
			}
		}

		private void AppIcon_MouseLeave(object sender, EventArgs e)
		{
			OnMouseLeave(e);
		}

		private void AppIcon_MouseEnter(object sender, EventArgs e)
		{
			OnMouseEnter(e);
		}

		private void MenuItemControl_MouseLeave(object sender, EventArgs e)
		{
			BackColor = Color.Transparent;
		}

		private void MenuItemControl_MouseEnter(object sender, EventArgs e)
		{
			BackColor = SystemColors.Highlight;
		}

		private void MenuItemControl_MouseClick(object sender, MouseEventArgs e)
		{
			BackColor = Color.Yellow;
			if (sender != this)
				this.OnMouseClick(e);
		}
	}
}
